package com.bobo.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bobo.demo.entity.ShakeBead;
import com.bobo.demo.entity.ShakeBeadApply;
import com.bobo.demo.mapper.ShakeBeadApplyMapper;
import com.bobo.demo.service.DemoService;
import com.bobo.demo.service.ShakeBeadApplyService;
import com.bobo.demo.service.ShakeBeadService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/Demo")
public class DemoController {

    private final DemoService demoService;

    private final ShakeBeadApplyService shakeBeadApplyService;

    private final ShakeBeadApplyMapper shakeBeadApplyMapper;

    private final ShakeBeadService shakeBeadService;


    @ResponseBody
    @RequestMapping("/getUserList")
    public String getUserList(){
//        demoService.getOne();

        return "String";
    }

    @ResponseBody
    @RequestMapping("/testShakeBead")
    public void testShakeBead() throws InterruptedException {//测试多线程环境下摇珠故障概率
        demoService.testShakeBead();
    }

    @ResponseBody
    @RequestMapping("/testShakeBeadApply")
    public void testShakeBead(@Param("shakeBeadId")Integer shakeBeadId){//测试多线程环境下摇珠故障概率
        /** 模拟有多个人申请一个案子摇珠*/
        List<ShakeBeadApply> sbs = new ArrayList<>();//ArrayList是线程不安全的
        System.out.println(shakeBeadId);
        for (int i = 1; i <= 20; i++) {
            ShakeBeadApply t = new ShakeBeadApply();
            t.setShakeBeadId(shakeBeadId);
            t.setTuserId(i);
            t.setTuserName("张"+i);
            sbs.add(t);
        }
        log.info("模拟有多个人申请一个案子摇珠结果：{}",shakeBeadApplyService.saveBatch(sbs));
    }


}
